package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Pattern;

import android.graphics.Bitmap;
import android.widget.Toast;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.game.Attribute;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.IconManger;
import com.handinfo.android.game.Role;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.game.item.ItemConstants;
import com.handinfo.android.game.item.ItemEquipment;
import com.handinfo.android.game.item.ItemGem;
import com.handinfo.android.game.item.VipShop;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWControl;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTabControl;
import com.handinfo.android.uicontrols.controls.DWTabPage;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
//import com.handinfo.android.utils.ChannelOperation;
import com.handinfo.android.utils.Tools;

public class UIShop implements IUIWindows{

	private int num = 0;
	private boolean flag = false;
	public DWFrame m_sp_frame = null;
	private DWTitle m_sp_title = null;
	private DWImageBox m_imageBox_title = null;
	private Bitmap m_bitmap_title = null;
	private DWImageBox m_ib_close = null;//关闭
	private Bitmap m_bm_close = null;
	private DWTabControl m_sp_tc = null;
	private Item m_buy_item;
	private int m_index = 0;

	private DWTextbox m_vip_tishi = null;
	//tape
	private String[] m_tabControl_str = {"热卖","礼盒","宝石","时装","坐骑","宠物","卡符","全部"};
	private DWTabPage[] m_sp_tabPage = new DWTabPage[m_tabControl_str.length];//tab页
	private DWListbox m_tabPage_listBox = null;//list
	//list
	private String[] m_remai = {"鞋子","帽子","腰带","衣服","裤子","刀","剑","砖","强"};
	private String[] m_remai_jiage = {"a鞋子","帽子","腰带","衣服","裤子","刀","剑","砖","强"};
	private String[] m_remai_shiyong = {"a鞋子","帽子","腰带","衣服","裤子","刀","剑","砖","强"};
	private String[] m_remai_tishi = {"a鞋子","帽子","腰带","衣服","裤子","刀","剑","砖","强"};
	private DWListSubItem[] m_listBox_item;
	private DWImageBox[] m_remai_background;
	private DWImageBox[] m_listBox_grid;//商品背景
	private DWImageBox[] m_grid_biankuang;//图标外边框
	private DWImageBox[] m_grid_tubiao;//商品图标
	private Bitmap m_bitmap_beijing = null;
	private Bitmap[] m_bitmap_biankuang;
	private Bitmap[] m_bitmap_tubiao;
	private DWTextbox[] m_listBox_tb_name;
	private DWTextbox[] m_listBox_tb_jiage;
	private DWTextbox[] m_listBox_tb_shiyong;
	private DWImageBox[] m_listBox_bt ;
	private DWImageBox[] m_imageBox_tishi;
	private Bitmap m_shangpin = null;
	private int m_jinting_remai = 0;
	//图标
	private Bitmap m_bm_remai = null;
	private Bitmap m_bm_dazhe = null;
	private Bitmap m_bm_xinpin = null;

	private DWBackground m_sp_background = null;
	private DWBackground m_background_left = null;
	private DWBackground m_background_right = null;
	private Bitmap m_sp_beijing01 = null;
	private Bitmap m_sp_beijing02 = null;
	private Bitmap m_picture_back = null;
	private Bitmap m_button_back = null;
	private DWImageBox m_ib_mm = null;
	private Bitmap m_bm_mm = null;
	private Bitmap m_bm_shuangchong = null;
	private Bitmap m_bm_chunjie = null;

	//充值
	private DWButton m_bt_chongzhi = null;
	private Bitmap m_bm_anniu01 = null;
	//查看充值
	private DWButton m_bt_chakan = null;
	private Bitmap m_bm_anniu02 = null;
	//查看充值记录
	private DWButton m_bt_jilu = null;

	public DWTextbox m_sp_yuanbao = null;

	// tab页（bitmap）
	private Bitmap m_bm_nochoose = null; // 未选中
	private Bitmap m_bm_choose = null; // 选中


	private void shopLook(){
		m_sp_frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_sp_frame.setClickClose(false);
		m_sp_title = new DWTitle("", m_sp_frame);

		m_image_title = new DWImageBox(m_bitmap_title);
		m_image_title.setNearAnchor(m_sp_title, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		// 关闭窗口
		m_ib_close = new DWImageBox(m_bm_close);
		m_ib_close.setTouchZoomIn(20, 20);
		m_ib_close.setNearAnchor(m_sp_title, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 0);
		//背景
//		m_sp_background = new DWBackground(680, 340);
////		m_sp_background.setFill(true);
//		m_sp_background.setNearAnchor(m_sp_frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 5);

		m_background_left = new DWBackground(230,340);
		if(DWGameManager.AdpaterType == 2){
			m_background_left.setShowWideHigh(DWGameManager.Screen_Width*23/80, DWGameManager.Screen_Height*34/48);
		}
		m_background_left.setFill(false);
		m_background_left.setShow(false);
		m_background_left.setNearAnchor(m_sp_frame,Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 0, 0);

		m_background_right = new DWBackground(530, 330);
		if(DWGameManager.AdpaterType == 2){
			m_background_right.setShowWideHigh(DWGameManager.Screen_Width*53/80, DWGameManager.Screen_Height*33/48);
		}
		m_background_right.setFill(false);
		m_background_right.setNearAnchor(m_background_left,Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);

		//记录、充值
		m_bt_chongzhi = new DWButton("充值", m_bm_anniu01);
		m_bt_chongzhi.setDownImage(m_bm_anniu02);
		m_bt_chongzhi.setNearAnchor(m_sp_frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -50, 0);

		m_bt_jilu = new DWButton("充值记录", m_bm_anniu01);
		m_bt_jilu.setDownImage(m_bm_anniu02);
		m_bt_jilu.setNearAnchor(m_bt_chongzhi, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, -20, 0);

		m_bt_chakan = new DWButton("VIP特权", m_bm_anniu01);
		m_bt_chakan.setDownImage(m_bm_anniu02);
		m_bt_chakan.setNearAnchor(m_bt_jilu, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, -20, 0);

		//文字提示。。
		m_sp_yuanbao = new DWTextbox("当前元宝："+DWGameManager.getInstance().m_role.m_rmb,200);
		m_sp_yuanbao.setNearAnchor(m_sp_frame, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 10, 0);

		// 人物形象
		m_ib_mm = new DWImageBox(m_bm_mm);
		m_ib_mm.setTouch(false);
		m_ib_mm.addListener(m_button_mm);
		m_ib_mm.setNearAnchor(m_background_left, Tools.HCENTER_VCENTER,Tools.HCENTER_VCENTER, 0,0);
		if(m_shop_status == 0){
			m_ib_mm.setBackground(m_bm_mm, false);
			m_ib_mm.setTouch(false);
		}else if(m_shop_status == 1){
			m_ib_mm.setBackground(m_bm_shuangchong, false);
			m_ib_mm.setTouch(true);
		}else if(m_shop_status == 2){
			m_ib_mm.setBackground(m_bm_chunjie, false);
			m_ib_mm.setTouch(true);
		}
		//vip入口
		m_vip_tishi = new DWTextbox("<mark c=0000FF> VIP入口</mark>");
		m_vip_tishi.setShow(false);
		m_vip_tishi.setNearAnchor(m_ib_mm, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 0, 0);

		// tab 容器
		m_sp_tc = new DWTabControl(m_bm_choose,m_bm_nochoose, m_sp_frame.getShowWidth(), m_sp_frame.getShowHeight());//670
		m_sp_tc.setNearAnchor(m_sp_title, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0,0);

		if(DWGameManager.AdpaterType == 2){
			m_tabPage_listBox = new DWListbox(m_background_right.getShowWidth(), m_background_right.getShowHeight());
		}else{
			m_tabPage_listBox = new DWListbox(500, 300);
		}
//		m_tabPage_listBox.setScrollbar(10);

		for(int i=0;i < m_tabControl_str.length;i++ ){
			m_sp_tabPage[i] = new DWTabPage();
			m_sp_tabPage[i].setName(m_tabControl_str[i]);
			if(DWGameManager.AdpaterType == 2){
				m_tabPage_listBox.setNearAnchor(m_sp_tabPage[i], Tools.LEFT_TOP, Tools.LEFT_TOP,400,0);
			}else{
				m_tabPage_listBox.setNearAnchor(m_sp_tabPage[i], Tools.LEFT_TOP, Tools.LEFT_TOP,250,0);
			}
			m_sp_tabPage[i].addControls(m_tabPage_listBox);
			m_sp_tc.addTabPage(m_sp_tabPage[i]);
		}
		if(m_type == 0){
			m_sp_tabPage[0].setSelect(false);
			m_sp_tabPage[3].setSelect(true);
		}else if(m_type == 1){
			m_sp_tabPage[0].setSelect(false);
			m_sp_tabPage[0].setSelect(true);
		}else if(m_type == 2){
			m_sp_tabPage[0].setSelect(false);
			m_sp_tabPage[1].setSelect(true);
		}else if(m_type == 3){
			m_sp_tabPage[0].setSelect(false);
			m_sp_tabPage[2].setSelect(true);
		}



		refreshShop();

//		Set<Entry<String, List<Item>>> entryset = map.entrySet();
//		 Iterator<Entry<String, List<Item>>>  it = entryset.iterator();
//		 while(it.hasNext()){
//			 Entry<String, List<Item>> entry  = it.next();
//			 entry.getKey();
//			 List<Item> list = entry.getValue();
//
//			 m_item_size = list.size();
////			 m_shop_item = new Item[m_item_size];
////
////			 for(int i = 0; i < m_item_size;i++){
////				 m_shop_getItem = list.get(i);
////			 }
//		 }
//
//		refreshShop();
		//主窗体以及父类控件
//		m_sp_frame.addControl(m_sp_background);
		m_sp_frame.addControl(m_background_left);
		m_sp_frame.addControl(m_background_right);
		m_sp_frame.addControl(m_sp_title);
		m_sp_frame.addControl(m_image_title);
		m_sp_frame.addControl(m_ib_close);
		m_sp_frame.addControl(m_sp_tc);
		m_sp_frame.addControl(m_ib_mm);
		m_sp_frame.addControl(m_vip_tishi);
		m_sp_frame.addControl(m_bt_chakan);
		m_sp_frame.addControl(m_bt_jilu);
		m_sp_frame.addControl(m_bt_chongzhi);
		m_sp_frame.addControl(m_sp_yuanbao);
//		m_sp_frame.addControl(m_tabPage_listBox);
		DWControlsManager.getInstance().addControl(m_sp_frame);

		// 关闭按钮的监听
		m_ib_close.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				UIWindows.getInstance().m_shop.close((byte)0);
			}
		});
		//vip入口
		m_bt_chakan.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				UIWindows.getInstance().m_shop.close((byte)0);
				DWGameManager.getInstance().getSendMessage().sendOpenVip();
//				UIWindows.getInstance().m_vip.open((byte)0);
//				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
//						"内测暂不开放！");
			}
		});
		//充值
		m_bt_chongzhi.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				//注释掉。。
//				if (ChannelOperation.isChanneSdkChongZhi) {
//					ChannelOperation.sdkPay();
//				}
//				else {
//					UIWindows.getInstance().m_shop.close((byte)0);
//					ChannelOperation.openChongZhiWindow();
//				}
			}
		});
		//充值记录
		m_bt_jilu.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				DWGameManager.getInstance().getSendMessage().sendOpenChongZhiJiLu();
			}
		});
		//vip入口(mm)
//		m_vip_tishi.addListener(new DWListener() {
//
//			public void OnDoubleClick() {
//			}
//
//			public void OnClick() {
//				UIWindows.getInstance().m_shop.close((byte)0);
//				UIWindows.getInstance().m_vip.open((byte)0);
////				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
////						"内测暂不开放！");
//			}
//		});
		//tc监听
		m_sp_tc.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				int index = m_sp_tc.getPageIndex();
				switch(index){
				case 0:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)1,(byte)1);
					break;
				case 1:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)2,(byte)1);
					break;
				case 2:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)3,(byte)1);
					break;
				case 3:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)4,(byte)1);
					break;
				case 4:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)5,(byte)1);
					break;
				case 5:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)6,(byte)1);
					break;
				case 6:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)7,(byte)1);
					break;
				case 7:
					DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte)0,(byte)1);
					break;

				}

			}
		});

	}

	private DWListener m_button_mm = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			lookHuoDong();
		}
	};
	private DWFrame m_huodong_frame = null;
	private DWTitle m_huodong_title = null;
	private DWBackground m_huodong_back = null;
	private DWTextbox[] m_huodong_text = new DWTextbox[5];
	private DWButton m_huodong_button = null;
	private DWImageBox m_huodong_close = null;
	private static final String str01 = "2月6日起所有玩家首次充值将获得充值元宝数量100%返还。";
	private static final String str02 = "例如：首冲1000元宝，返还1000元宝。";
	private static final String str03 = "例如：充值1000元宝，返还充值10%元宝";

	//活动界面
	private void lookHuoDong(){
		m_huodong_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_huodong_frame.setClickClose(false);
		m_huodong_title = new DWTitle("新春活动", m_huodong_frame);

		m_huodong_close = new DWImageBox(m_bm_close);
		m_huodong_close.addListener(m_huodong_guanbi);
		m_huodong_close.setNearAnchor(m_huodong_title,Tools.RIGHT_BOTTOM,Tools.RIGHT_BOTTOM,0,0);

		m_huodong_back = new DWBackground(m_huodong_frame.getShowWidth(), m_huodong_frame.getShowHeight());
		m_huodong_back.setNearAnchor(m_huodong_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);

		m_huodong_text[0] = new DWTextbox(str01,m_huodong_back.getShowWidth()-50);
		m_huodong_text[0].setNearAnchor(m_huodong_back, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, DWGameManager.Screen_Height*5/72);

		m_huodong_text[1] = new DWTextbox("<mark c=FFBB11>首冲元宝返还：</mark>",m_huodong_back.getShowWidth()-DWGameManager.Screen_Height*5/72);
		m_huodong_text[1].setNearAnchor(m_huodong_text[0], Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, DWGameManager.Screen_Height*5/72);

		m_huodong_text[2] = new DWTextbox(str02,m_huodong_back.getShowWidth()-50);
		m_huodong_text[2].setNearAnchor(m_huodong_text[1], Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, DWGameManager.Screen_Height/72);

		m_huodong_text[3] = new DWTextbox("");
		m_huodong_text[3].setNearAnchor(m_huodong_text[2], Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, DWGameManager.Screen_Height*5/72);

		m_huodong_text[4] = new DWTextbox("");
		m_huodong_text[4].setNearAnchor(m_huodong_text[3], Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, DWGameManager.Screen_Height/72);

		m_huodong_button = new DWButton("充值", m_bm_anniu01);
		m_huodong_button.setDownImage(m_bm_anniu02);
		m_huodong_button.addListener(m_huodong_chongzhi);
		m_huodong_button.setNearAnchor(m_huodong_back, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);

		m_huodong_frame.addControl(m_huodong_back);
		m_huodong_frame.addControl(m_huodong_title);
		m_huodong_frame.addControl(m_huodong_close);
		for(int i=0;i<5;i++){
			m_huodong_frame.addControl(m_huodong_text[i]);
		}

		m_huodong_frame.addControl(m_huodong_button);

		DWControlsManager.getInstance().addControl(m_huodong_frame);

	}

	private DWListener m_huodong_guanbi = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			DWControlsManager.getInstance().removeControl(m_huodong_frame);
		}
	};

	private DWListener m_huodong_chongzhi = new DWListener() {
		public void OnDoubleClick() {
		}

		public void OnClick() {
			//注释掉。。
//			if (ChannelOperation.isChanneSdkChongZhi) {
//				ChannelOperation.sdkPay();
//			}
//			else {
//				UIWindows.getInstance().m_shop.close((byte)0);
//				DWControlsManager.getInstance().removeControl(m_huodong_frame);
//				ChannelOperation.openChongZhiWindow();
//			}

		}
	};

	/**
	 * 刷新tab页内容
	 */
	public void refreshShop(){
		m_tabPage_listBox.removeAllSubItem();
		m_listBox_item = new DWListSubItem[m_item_size];
		m_remai_background = new DWImageBox[m_item_size];
		m_listBox_grid = new DWImageBox[m_item_size];//商品图标
		m_grid_biankuang = new DWImageBox[m_item_size];
		m_grid_tubiao = new DWImageBox[m_item_size];
//		m_bitmap_beijing = new Bitmap[m_item_size];
		m_bitmap_biankuang = new Bitmap[m_item_size];
		m_bitmap_tubiao = new Bitmap[m_item_size];
		m_listBox_tb_name = new DWTextbox[m_item_size];
		m_listBox_tb_jiage = new DWTextbox[m_item_size];
		m_listBox_tb_shiyong = new DWTextbox[m_item_size];
		m_listBox_bt = new DWImageBox[m_item_size];
		m_imageBox_tishi = new DWImageBox[m_item_size];

		for(int i = 0;i < m_item_size/2+m_item_size%2;i++){
			m_listBox_item[i] = new DWListSubItem();//构造一半subItem
		}


		for(int i=0;i< m_item_size;i++){
			final int index = i;
			if(i%2 == 0){//双数，放在左侧
				m_remai_background[i] = new DWImageBox(m_picture_back); //小背景
				m_remai_background[i].setShowWideHigh(250, 100);
				if(DWGameManager.AdpaterType == 2){
					m_remai_background[i].setShowWideHigh(m_tabPage_listBox.getShowWidth()/2-10, m_tabPage_listBox.getShowHeight()/3);
				}
				m_remai_background[i].setNearAnchor(m_listBox_item[i/2], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				//促销提示
				m_imageBox_tishi[i] = new DWImageBox(m_bm_remai);
				m_imageBox_tishi[i].setNearAnchor(m_remai_background[i], Tools.RIGHT_TOP, Tools.RIGHT_TOP, -10, 10);
				if(m_shop_item[i].m_label_right == 0){
					m_imageBox_tishi[i].setShow(false);
				}else if(m_shop_item[i].m_label_left == 1){//打折
					m_imageBox_tishi[i].setBackground(m_bm_dazhe, true);
				}else if(m_shop_item[i].m_label_left == 2){//热卖
					m_imageBox_tishi[i].setBackground(m_bm_remai, true);
				}else if(m_shop_item[i].m_label_left == 3){//新品
					m_imageBox_tishi[i].setBackground(m_bm_xinpin, true);
				}
				//商品边框
				m_bitmap_biankuang[i] = IconManger.getInstance().getPinzhi(m_shop_item[i].m_border);
				m_grid_biankuang[i] = new DWImageBox(m_bitmap_biankuang[i]);
				m_grid_biankuang[i].setNearAnchor(m_remai_background[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);

				m_listBox_grid[i] = new DWImageBox(m_bitmap_beijing);//商品图标
				if(DWGameManager.AdpaterType == 2){
					m_listBox_grid[i].setShowWideHigh(DWGameManager.Screen_Width*64/800, DWGameManager.Screen_Height*64/480);
				}
				m_listBox_grid[i].setNearAnchor(m_grid_biankuang[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
				//商品图标
				m_bitmap_tubiao[i] = IconManger.getInstance().getIcon(m_shop_item[i].m_iconId);
				m_grid_tubiao[i] = new DWImageBox(m_bitmap_tubiao[i]);
				m_grid_tubiao[i].setNearAnchor(m_grid_biankuang[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				m_listBox_tb_name[i] = new DWTextbox("<mark c=55FF00>"+m_shop_item[i].m_name+"</mark>");//商品名字a
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_name[i].setFont(DWFont.getFont(22));
				}else{
					m_listBox_tb_name[i].setFont(DWFont.getFont(16));
				}
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_name[i].setNearAnchor(m_listBox_grid[i], Tools.LEFT_TOP, Tools.RIGHT_TOP, 30, 20);
				}else{
					m_listBox_tb_name[i].setNearAnchor(m_listBox_grid[i], Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 10);
				}

				m_listBox_tb_jiage[i] = new DWTextbox(String.valueOf(m_shop_item[i].m_yuanbaoPrice)+"<mark c=55FF00>元宝</mark>");//商品价格
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_jiage[i].setFont(DWFont.getFont(24));
				}else{
					m_listBox_tb_jiage[i].setFont(DWFont.getFont(18));
				}
				m_listBox_tb_jiage[i].setNearAnchor(m_remai_background[i], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -10, -10);
				m_listBox_tb_shiyong[i] = new DWTextbox("今天还可以购买"+(m_vipShop[i].m_canBuy-m_vipShop[i].m_surplus)+"个");//vip提示 "<mark c=FFBB11>vip"+m_vipShop[i].m_vipLevel+"级</mark>"
//				if(m_vipShop[i].m_vipLevel == 0){
//					m_listBox_tb_shiyong[i].setText("<mark c=FFBB11>普通用户</mark>");
//				}
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_shiyong[i].setFont(DWFont.getFont(22));
				}else{
					m_listBox_tb_shiyong[i].setFont(DWFont.getFont(16));
				}
				m_listBox_tb_shiyong[i].setNearAnchor(m_listBox_tb_name[i], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
//				m_listBox_tb_tishi[i] = new DWTextbox("还可以购买"+(m_vipShop[i].m_canBuy-m_vipShop[i].m_surplus)+"个");//商品提示
//				m_listBox_tb_tishi[i].setShow(false);
//				m_listBox_tb_tishi[i].setFont(DWFont.getFont(16));
//				m_listBox_tb_tishi[i].setNearAnchor(m_listBox_grid[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 5, 70);
				m_listBox_bt[i] = new DWImageBox(m_button_back);
				m_listBox_bt[i].setShowWideHigh(245, 95);
				if(DWGameManager.AdpaterType == 2){
					m_listBox_bt[i].setShowWideHigh(m_tabPage_listBox.getShowWidth()/2-20, m_tabPage_listBox.getShowHeight()/3-10);
				}
				m_listBox_bt[i].setShow(false);
				m_listBox_bt[i].setNearAnchor(m_remai_background[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);

				if(m_vipShop[i].m_canBuy == 0){
					m_listBox_tb_shiyong[i].setText("<mark c=FF0000>vip"+m_vipShop[i].m_surplus+"</mark>可以购买");
//					m_listBox_tb_tishi[i].setShow(false);
//					m_listBox_tb_tishi[i].setText("");
				}

				m_listBox_item[i/2].addControls(m_remai_background[i]);
				m_listBox_item[i/2].addControls(m_imageBox_tishi[i]);
				m_listBox_item[i/2].addControls(m_listBox_grid[i]);
				m_listBox_item[i/2].addControls(m_grid_biankuang[i]);
				m_listBox_item[i/2].addControls(m_grid_tubiao[i]);
				m_listBox_item[i/2].addControls(m_listBox_tb_name[i]);
				m_listBox_item[i/2].addControls(m_listBox_tb_jiage[i]);
				m_listBox_item[i/2].addControls(m_listBox_tb_shiyong[i]);
//				m_listBox_item[i].addControls(m_listBox_tb_tishi[i]);
				m_listBox_item[i/2].addControls(m_listBox_bt[i]);
				m_tabPage_listBox.addSubItem(m_listBox_item[i/2]);
			}else{
				m_remai_background[i] = new DWImageBox(m_picture_back); //小背景
				m_remai_background[i].setShowWideHigh(250, 100);
				if(DWGameManager.AdpaterType == 2){
					m_remai_background[i].setShowWideHigh(m_tabPage_listBox.getShowWidth()/2-10, m_tabPage_listBox.getShowHeight()/3);
				}
				if(DWGameManager.AdpaterType == 2){
					m_remai_background[i].setNearAnchor(m_listBox_item[i-i/2-i%2], Tools.LEFT_TOP, Tools.LEFT_TOP, m_tabPage_listBox.getShowWidth()/2, 0);
				}else{
					m_remai_background[i].setNearAnchor(m_listBox_item[i-i/2-i%2], Tools.LEFT_TOP, Tools.LEFT_TOP, 250, 0);
				}

				//促销提示
				m_imageBox_tishi[i] = new DWImageBox(m_bm_remai);
				m_imageBox_tishi[i].setNearAnchor(m_remai_background[i], Tools.RIGHT_TOP, Tools.RIGHT_TOP, -10, 10);
				if(m_shop_item[i].m_label_right == 0){
					m_imageBox_tishi[i].setShow(false);
				}else if(m_shop_item[i].m_label_left == 1){//打折
					m_imageBox_tishi[i].setBackground(m_bm_dazhe, true);
				}else if(m_shop_item[i].m_label_left == 2){//热卖
					m_imageBox_tishi[i].setBackground(m_bm_remai, true);
				}else if(m_shop_item[i].m_label_left == 3){//新品
					m_imageBox_tishi[i].setBackground(m_bm_xinpin, true);
				}
				//商品边框
				m_bitmap_biankuang[i] = IconManger.getInstance().getPinzhi(m_shop_item[i].m_border);
				m_grid_biankuang[i] = new DWImageBox(m_bitmap_biankuang[i]);
				m_grid_biankuang[i].setNearAnchor(m_remai_background[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);

				m_listBox_grid[i] = new DWImageBox(m_bitmap_beijing);//商品图标
				if(DWGameManager.AdpaterType == 2){
					m_listBox_grid[i].setShowWideHigh(DWGameManager.Screen_Width*64/800, DWGameManager.Screen_Height*64/480);
				}
				m_listBox_grid[i].setNearAnchor(m_grid_biankuang[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
				//商品图标
				m_bitmap_tubiao[i] = IconManger.getInstance().getIcon(m_shop_item[i].m_iconId);
				m_grid_tubiao[i] = new DWImageBox(m_bitmap_tubiao[i]);
				m_grid_tubiao[i].setNearAnchor(m_grid_biankuang[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				m_listBox_tb_name[i] = new DWTextbox("<mark c=55FF00>"+m_shop_item[i].m_name+"</mark>");//商品名字a
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_name[i].setFont(DWFont.getFont(22));
				}else{
					m_listBox_tb_name[i].setFont(DWFont.getFont(16));
				}
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_name[i].setNearAnchor(m_listBox_grid[i], Tools.LEFT_TOP, Tools.RIGHT_TOP, 30, 20);
				}else{
					m_listBox_tb_name[i].setNearAnchor(m_listBox_grid[i], Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 10);
				}
				m_listBox_tb_jiage[i] = new DWTextbox(String.valueOf(m_shop_item[i].m_yuanbaoPrice)+"<mark c=55FF00>元宝</mark>");//商品价格
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_jiage[i].setFont(DWFont.getFont(24));
				}else{
					m_listBox_tb_jiage[i].setFont(DWFont.getFont(18));
				}
				m_listBox_tb_jiage[i].setNearAnchor(m_remai_background[i], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -10, -10);
				m_listBox_tb_shiyong[i] = new DWTextbox("今天还可以购买"+(m_vipShop[i].m_canBuy-m_vipShop[i].m_surplus)+"个");//vip提示
//				if(m_vipShop[i].m_vipLevel == 0){
//					m_listBox_tb_shiyong[i].setText("<mark c=FFBB11>普通用户</mark>");
//				}
				if(DWGameManager.AdpaterType == 2){
					m_listBox_tb_shiyong[i].setFont(DWFont.getFont(22));
				}else{
					m_listBox_tb_shiyong[i].setFont(DWFont.getFont(16));
				}
				m_listBox_tb_shiyong[i].setNearAnchor(m_listBox_tb_name[i], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
//				m_listBox_tb_tishi[i] = new DWTextbox("还可以购买"+(m_vipShop[i].m_canBuy-m_vipShop[i].m_surplus)+"个");//商品提示
//				m_listBox_tb_tishi[i].setFont(DWFont.getFont(16));
//				m_listBox_tb_tishi[i].setShow(false);
//				m_listBox_tb_tishi[i].setNearAnchor(m_listBox_grid[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 5, 70);
				m_listBox_bt[i] = new DWImageBox(m_button_back);
				m_listBox_bt[i].setShowWideHigh(245, 95);
				if(DWGameManager.AdpaterType == 2){
					m_listBox_bt[i].setShowWideHigh(m_tabPage_listBox.getShowWidth()/2-20, m_tabPage_listBox.getShowHeight()/3-10);
				}
				m_listBox_bt[i].setShow(false);
				m_listBox_bt[i].setNearAnchor(m_remai_background[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				if(m_vipShop[i].m_canBuy == 0){
					m_listBox_tb_shiyong[i].setText("<mark c=FF0000>vip"+m_vipShop[i].m_surplus+"</mark>可以购买");
//					m_listBox_tb_tishi[i].setText("");
				}
				m_listBox_item[i-i/2-i%2].addControls(m_remai_background[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_imageBox_tishi[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_listBox_grid[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_grid_biankuang[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_grid_tubiao[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_listBox_tb_name[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_listBox_tb_jiage[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_listBox_tb_shiyong[i]);
//				m_listBox_item[i-i/2-i%2].addControls(m_listBox_tb_tishi[i]);
				m_listBox_item[i-i/2-i%2].addControls(m_listBox_bt[i]); //i-i/2-i%2 != i/2-i%2
//				int b = i-m_item_size/2-m_item_size%2;
			}

			//监听（购买按钮）
			m_listBox_bt[index].addListener(new DWListener() {
				public void OnDoubleClick() {
				}

				public void OnClick() {
					m_buy_item = m_shop_item[index];
					m_buy_vipShop = m_vipShop[index];
					m_index = index;
					DWGameManager.getInstance().getSendMessage().sendLookVipShopItem(m_buy_item.m_key);
				}
			});
		}
	}

	/*****************************************购买界面******************************************/
	private int m_num = 1;
	private DWFrame m_buy_frame = null;
	private DWTitle m_buy_title = null;
	private DWImageBox m_image_title = null;
	private DWImageBox m_buy_close = null;
	private Bitmap m_bm_title = null;
	private DWBackground m_buy_backGround = null;
	private Bitmap m_bm_beijing = null;
	private DWImageBox m_image_close = null;
	private DWListbox m_buy_listBox = null;
	private DWListSubItem m_buy_subItem = null;
	private DWTextbox m_buy_textBox = null;//购买
	private DWInputBox m_buy_inputBox = null;
	private DWImageBox m_imageBox_left = null;
	private DWImageBox m_imageBox_right = null;
	private Bitmap m_bm_left = null;
	private Bitmap m_bm_right = null;
	private DWTextbox m_textBox_money = null;//价格
	private DWButton m_buy_button = null;
	public static final String[][] 类型名称 = {
		{ "武器", "头部", "上衣", "腰带", "裤子", "鞋子", "称号", "项链", "手腕", "戒指", "时装", "法宝", "护符", "坐骑", "预留1", "预留2" },
		{ "", "血蓝药", "状态药", "增强药", "传送券", "触发任务卷", "礼包", "喇叭", "宝箱1", "商城道具", "宝箱2", "宠物蛋", "", "" },
		{ "", "宝石" },
		{ "", "任务", "特殊功能", "钥匙" }
	};
	public static final String[] 装备_绑定类型 = { "不绑定", "装备后绑定", "拾取后绑定", "使用后绑定" };
	public static final String[] 装备_基础属性 = { "物理攻击", "法术攻击", "物理防御", "法术防御" };
	DWControl lastControl;
	public void buyItem(Item item){
		if(m_buy_vipShop != null){
			if(m_buy_vipShop.m_canBuy > m_buy_vipShop.m_surplus){
				m_num = 1;
			}else{
				m_num = 0;
			}

		}

//		if(m_textBox_money != null){
//			int price = m_buy_item.m_yuanbaoPrice * m_num;
//			m_textBox_money.setText("价格:"+price+"元宝");
//		}
		m_buy_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_buy_frame.setClickClose(true);
		m_buy_title = new DWTitle("购买", m_buy_frame);

		m_image_close = new DWImageBox(m_bm_close);
		m_image_close.setNearAnchor(m_buy_title, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 0);
		m_buy_backGround = new DWBackground(m_sp_beijing01,m_buy_frame.getShowWidth(), m_buy_frame.getShowHeight());
		m_buy_backGround.setNearAnchor(m_buy_frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_buy_frame.addControl(m_buy_backGround);


		if(DWGameManager.AdpaterType == 2){
			m_buy_listBox = new DWListbox(m_buy_frame.getShowWidth() - 50, 400);
		}else{
			m_buy_listBox = new DWListbox(300, 300);
		}
		m_buy_listBox.setNearAnchor(m_buy_title	, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 20, 10);

		m_buy_subItem = new DWListSubItem();
		infoItem(item);

		m_buy_textBox = new DWTextbox("购买");
		if(DWGameManager.AdpaterType == 2){
			m_buy_textBox.setNearAnchor(m_buy_listBox, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 50);
		}else{
			m_buy_textBox.setNearAnchor(m_buy_listBox, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
		}

		m_imageBox_left = new DWImageBox(m_bm_left);
		m_imageBox_left.addListener(m_left);
		if(DWGameManager.AdpaterType == 2){
			m_imageBox_left.setNearAnchor(m_buy_textBox, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 50, 0);
		}else{
			m_imageBox_left.setNearAnchor(m_buy_textBox, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);
		}

		m_buy_inputBox = new DWInputBox(100, m_buy_textBox.getShowWidth(), m_buy_frame);
		m_buy_inputBox.setText(""+m_num);
		m_buy_inputBox.addListener(m_inputBox);
		m_buy_inputBox.setNearAnchor(m_imageBox_left, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);

		m_imageBox_right = new DWImageBox(m_bm_right);
		m_imageBox_right.addListener(m_right);
		m_imageBox_right.setNearAnchor(m_buy_inputBox, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);

		//购买价格
		m_textBox_money = new DWTextbox("价格:"+m_buy_item.m_yuanbaoPrice+"元宝", 200);
		if(DWGameManager.AdpaterType == 2){
			m_textBox_money.setNearAnchor(m_buy_textBox, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 30);
		}else{
			m_textBox_money.setNearAnchor(m_buy_textBox, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
		}

		m_buy_button = new DWButton("购买", m_button_back);
		m_buy_button.addListener(m_buyButton);
		m_buy_button.setNearAnchor(m_buy_frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);

		m_buy_frame.addControl(m_buy_title);
		m_buy_frame.addControl(m_image_close);
		m_buy_frame.addControl(m_buy_listBox);
		m_buy_frame.addControl(m_imageBox_left);
		m_buy_frame.addControl(m_buy_textBox);
		m_buy_frame.addControl(m_buy_inputBox);
		m_buy_frame.addControl(m_imageBox_right);
		m_buy_frame.addControl(m_textBox_money);
		m_buy_frame.addControl(m_buy_button);
		DWControlsManager.getInstance().addControl(m_buy_frame);

		m_image_close.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				UIWindows.getInstance().m_shop.close((byte)1);
			}
		});

	}

	 public static boolean isNumber(String str){
		  Pattern pattern = Pattern.compile("[0-9]*");
		  Tools.debugPrintln("aaaaaaaaaaaa"+pattern.matcher(str).matches());
		  if(pattern.matcher(str).matches() == false){
			  DWGameManager.getInstance().showToast("请输入数字", Toast.LENGTH_SHORT);
		  }
		  return pattern.matcher(str).matches();
		 }
	//购买
		private DWListener m_buyButton = new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				int numSend = Integer.valueOf(m_buy_inputBox.getText());
				if(numSend ==0){
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
							"您已无法购买！");
					return;
				}
				DWGameManager.getInstance().getSendMessage().sendVipShopBuy(m_buy_item.m_key, (byte)numSend);
				m_num = 1;
				UIWindows.getInstance().m_shop.close((byte)1);
			}
		};
		//inputBox
		private DWListener m_inputBox = new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				int limitNum = 0;
				if(m_buy_item != null){
					if(m_buy_vipShop.m_canBuy >= m_buy_vipShop.m_surplus){
						limitNum = m_buy_vipShop.m_canBuy - m_buy_vipShop.m_surplus;
					}else{
						limitNum = 0;
					}
				}
				if(isNumber(m_buy_inputBox.getText().toString()) == true){//输入的是一个数字
					m_num = Integer.parseInt(m_buy_inputBox.getText().toString());
					if(m_num < 1 || m_num > 99){
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
								"请输入1-99");
						if(limitNum ==0){
							m_num = limitNum;
						}else{
							m_num = 1;
						}
						m_buy_inputBox.setText(""+m_num);
					}else{
						if(m_num > limitNum){
							DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
									"您没有这么多剩余购买数量！");
							m_num = limitNum;
							m_buy_inputBox.setText(""+m_num);
						}else{
							m_buy_inputBox.setText(""+m_num);
							}
					}
					int price = m_buy_item.m_yuanbaoPrice * m_num;
					m_textBox_money.setText("价格:"+price+"元宝");
				}else{
					if(limitNum ==0){
						m_num = limitNum;
					}else{
						m_num = 1;
					}
					m_buy_inputBox.setText(""+m_num);
					int price = m_buy_item.m_yuanbaoPrice * m_num;
					m_textBox_money.setText("价格:"+price+"元宝");
				}
			}
		};
		//减少
		private DWListener m_left = new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				if(m_num == 0){
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
							"您当前vip今日已无法购买此商品！");
					return;
				}

				if(m_num == 1){
					return;
				}else{
					m_num--;
					m_buy_inputBox.setText(""+m_num);
					int price = m_buy_item.m_yuanbaoPrice * m_num;
					m_textBox_money.setText("价格:"+price+"元宝");
				}

			}
		};
		//增加
		private DWListener m_right = new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				if(m_num == 0){
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
							"您当前vip今日已无法购买此商品！");
					return;
				}
				int limitNum = 0;
				if(m_buy_vipShop != null){
					if(m_buy_vipShop.m_canBuy >= m_buy_vipShop.m_surplus){
						limitNum = m_buy_vipShop.m_canBuy - m_buy_vipShop.m_surplus;
					}else{
						limitNum = 0;
					}

				}
				if (m_num == limitNum) {
					return;
				} else {
					m_num++;
					m_buy_inputBox.setText(""+m_num);
					int price = m_buy_item.m_yuanbaoPrice * m_num;
					m_textBox_money.setText("价格:"+price+"元宝");
				}

			}
		};
	//详情
	private void infoItem(Item m_buy_item01){
		Bitmap m_grid = IconManger.getInstance().getIcon(m_buy_item01.m_iconId);
		DWGrid m_buy_grid = new DWGrid(m_grid);
		m_buy_subItem.addControls(m_buy_grid);
		m_buy_grid.setNearAnchor(m_buy_subItem, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
		//装备名称
		lastControl = null;
				String name = "<mark c=" + UIBag.getNameColor(m_buy_item01.m_quality) + ">" + m_buy_item01.m_name + "</mark>";
				if (m_buy_item01.m_type == ItemConstants.道具类型_装备) {
					if (((ItemEquipment) m_buy_item01).m_strengthenLevel > 0)
						name += "<mark c=FFBB11>("
								+ ((ItemEquipment) m_buy_item01).getProductOrder(((ItemEquipment) m_buy_item01).m_strengthenLevel) + ")</mark>";
				}

				DWTextbox item_equip_name = new DWTextbox(name, 200);
				item_equip_name.setNearAnchor(m_buy_grid, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 20, 0);
				m_buy_subItem.addControls(item_equip_name);

				//装备类别
				Tools.debugPrintln("item.m_type=" + m_buy_item01.m_type + "item.m_subtype=" + m_buy_item01.m_subtype);
				String type = "<mark c=FFBB11>类别：</mark>";
				if (类型名称.length > (m_buy_item01.m_type - 1) && 类型名称[m_buy_item01.m_type - 1].length > m_buy_item01.m_subtype)
				{
					type += 类型名称[m_buy_item01.m_type - 1][m_buy_item01.m_subtype];
				}
				if (m_buy_item01.m_bindingState == ItemConstants.绑定状态_是) {
					type += "  已绑定";
				}
				else if (m_buy_item01.m_bindingState == ItemConstants.绑定状态_否) {
					type += "  " + 装备_绑定类型[m_buy_item01.m_bindingType];
				}

				DWTextbox item_equip_type = new DWTextbox(type, 200);
				item_equip_type.setNearAnchor(m_buy_grid, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 20);
				m_buy_subItem.addControls(item_equip_type);

				lastControl = item_equip_type;

				//装备评分
				if (m_buy_item01.m_type == ItemConstants.道具类型_装备 && ((ItemEquipment) m_buy_item01).m_gs>0) {

					DWTextbox item_equip_gs = new DWTextbox("<mark c=FFBB11>装备评分:</mark>" + ((ItemEquipment) m_buy_item01).m_gs,
							200);
					item_equip_gs.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
					m_buy_subItem.addControls(item_equip_gs);

					lastControl = item_equip_gs;
				}

				//使用限制
				String limit = "<mark c=FFBB11>使用限制:</mark>";
				if (m_buy_item01.m_minLevelLimit > 0) {
					limit += m_buy_item01.m_minLevelLimit + "级以上使用";
				}
				if (m_buy_item01.m_maxLevelLimit > 0) {
					limit += m_buy_item01.m_maxLevelLimit + "级以下使用";
				}
				String str = "   " + Role.ROLE_VOCATION_LIST[m_buy_item01.m_jobLimit];
				if (m_buy_item01.m_isLimit) {
					str = "<mark c=FF3300>" + str + "</mark>";
				}

				if (m_buy_item01.m_jobLimit > 0)
					limit += str;

				if (!limit.trim().equals("<mark c=FFBB11>使用限制:</mark>"))
				{
					DWTextbox item_equip_Limit = new DWTextbox(limit, 200);
					item_equip_Limit.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
					m_buy_subItem.addControls(item_equip_Limit);

					lastControl = item_equip_Limit;
				}

				//耐久值
				if (m_buy_item01.m_type == ItemConstants.道具类型_装备 && ((ItemEquipment) m_buy_item01).m_nowDurable != 0) {
					String durable = "<mark c=FFBB11>耐久值：</mark>";

					durable += ((ItemEquipment) m_buy_item01).m_nowDurable + "/" + ((ItemEquipment) m_buy_item01).m_maxDurable;
					DWTextbox item_equip_Durable = new DWTextbox(durable, 200);
					item_equip_Durable.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
					m_buy_subItem.addControls(item_equip_Durable);
					lastControl = item_equip_Durable;
				}

				//基础属性
				if (m_buy_item01.m_type == ItemConstants.道具类型_装备) {
					String baseDate = "";
					for (int i = 0; i < 4; i++) {
						if (((ItemEquipment) m_buy_item01).m_attrValue[i + Attribute.PHY_ATTACK] != 0) {
							baseDate += "<mark c=FFBB11>" + Attribute.ATTRIBUTE_NAME[i + Attribute.PHY_ATTACK] + "：</mark>";
							baseDate += ((ItemEquipment) m_buy_item01).m_attrValue[i + Attribute.PHY_ATTACK];

							if (((ItemEquipment) m_buy_item01).m_attrAddValue[i + Attribute.PHY_ATTACK] > 0) {
								baseDate += "    <mark c=FFBB11>+"
										+ ((ItemEquipment) m_buy_item01).m_attrAddValue[i + Attribute.PHY_ATTACK] + "</mark>";
							}else if(((ItemEquipment) m_buy_item01).m_attrAddValue[i + Attribute.PHY_ATTACK] < 0)
								baseDate += "    <mark c=FF3300>"
										+ ((ItemEquipment) m_buy_item01).m_attrAddValue[i + Attribute.PHY_ATTACK] + "</mark>";
							if (i != 3)
								baseDate += "`";
						}
					}
					if (!baseDate.equals("")) {
						DWTextbox item_equip_baseDate = new DWTextbox(baseDate, 200);
						item_equip_baseDate.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
						m_buy_subItem.addControls(item_equip_baseDate);

						lastControl = item_equip_baseDate;
					}

					//镶嵌宝石宝石

					if (((ItemEquipment) m_buy_item01).m_equipGemsSize > 0) {
						DWImageBox gemsImg[] = new DWImageBox[((ItemEquipment) m_buy_item01).m_equipGemsSize];
						for (int i = 0; i < gemsImg.length; i++) {
							gemsImg[i] = new DWImageBox(((ItemEquipment) m_buy_item01).m_gemSamllIcon[i]);
							DWTextbox gemsMsg = new DWTextbox("<mark c=FFBB11> " + ((ItemEquipment) m_buy_item01).getGemDatas(i)
									+ "</mark>");
							if (i % 2 == 0) {
								gemsImg[i].setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
								lastControl = gemsImg[i];
							}
							else {
								gemsImg[i].setNearAnchor(gemsImg[i - 1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 100, 0);
							}
							gemsMsg.setNearAnchor(gemsImg[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
							m_buy_subItem.addControls(gemsImg[i]);
							m_buy_subItem.addControls(gemsMsg);
						}
					}
				}

				//随机的附加属性
				if (m_buy_item01.m_type == ItemConstants.道具类型_装备) {
					StringBuilder attrValue = new StringBuilder();
					for (int i = 0; i < ((ItemEquipment) m_buy_item01).m_attrValue.length; i++) {
						if (i > Attribute.SPEED && i < Attribute.HIT)
							continue;

						if (((ItemEquipment) m_buy_item01).m_attrValue[i] > 0) {
							attrValue.append("<mark c=00FF00>" + Attribute.ATTRIBUTE_NAME[i] + ":+"
									+ ((ItemEquipment) m_buy_item01).m_attrValue[i] + "</mark>`");
						}
						else if (((ItemEquipment) m_buy_item01).m_attrValue[i] < 0) {
							attrValue.append("<mark c=999999>" + Attribute.ATTRIBUTE_NAME[i] + ":"
									+ ((ItemEquipment) m_buy_item01).m_attrValue[i] + "</mark>`");
						}
					}

					if (attrValue != null && attrValue.length() > 0) {
						DWTextbox item_equip_attrValue = new DWTextbox(attrValue.toString(), 200);
						item_equip_attrValue.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
						m_buy_subItem.addControls(item_equip_attrValue);

						lastControl = item_equip_attrValue;
					}
				}
				else if (m_buy_item01.m_type == ItemConstants.道具类型_宝石) {
					String attrValue = "<mark c=00FF00>" + Attribute.ATTRIBUTE_NAME[((ItemGem) m_buy_item01).m_attrindex] + ": +"
							+ ((ItemGem) m_buy_item01).m_attrvalue + "</mark>";
					DWTextbox item_equip_attrValue = new DWTextbox(attrValue, 200);
					item_equip_attrValue.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
					m_buy_subItem.addControls(item_equip_attrValue);
					lastControl = item_equip_attrValue;
				}

				//套装

				//描述
				if (m_buy_item01.m_descl != null && !(m_buy_item01.m_descl.equals(""))) {
					String prodyctOrder = "";
					prodyctOrder = "<mark c=FFFFFF>" + m_buy_item01.m_descl + "</mark>";

					DWTextbox item_equip_prodyctOrder = new DWTextbox(prodyctOrder, 200);
					item_equip_prodyctOrder.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
					m_buy_subItem.addControls(item_equip_prodyctOrder);
					lastControl = item_equip_prodyctOrder;
				}

				//寄宿精魂

				//解绑次数
				if (m_buy_item01.m_maxUnbindingTimes > 0)
				{
					String bindingTimes = "<mark c=FFBB11>解绑次数：</mark>"
							+ (m_buy_item01.m_maxUnbindingTimes - m_buy_item01.m_usedUnbindingTimes)
							+ "/" + m_buy_item01.m_maxUnbindingTimes;
					DWTextbox item_equip_bindingTimes = new DWTextbox(bindingTimes, 200);
					item_equip_bindingTimes.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
					m_buy_subItem.addControls(item_equip_bindingTimes);
					lastControl = item_equip_bindingTimes;
				}

				//限制时间
				if (m_buy_item01.m_lifecycle > 0)
				{
					DWTextbox item_equip_lifecycle = new DWTextbox("<mark c=FFBB11>限制时间：</mark>"
							+ (m_buy_item01.m_lifecycle > 0 ? UIBag.getTime(m_buy_item01.m_lifecycle,UIBag.DAYTYPE) : "无"), 200);
					item_equip_lifecycle.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
					m_buy_subItem.addControls(item_equip_lifecycle);
					lastControl = item_equip_lifecycle;
				}

				//出售价格

				DWTextbox item_equip_goldPrice = new DWTextbox("<mark c=FFBB11>出售价格：</mark>" + m_buy_item01.m_goldPrice, 200);
				item_equip_goldPrice.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
				m_buy_subItem.addControls(item_equip_goldPrice);
				lastControl = item_equip_goldPrice;

				//
				DWTextbox item_equip_end = new DWTextbox("<mark c=FFFFFF></mark>", 200);
				item_equip_end.setNearAnchor(lastControl, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
				m_buy_subItem.addControls(item_equip_end);
				m_buy_listBox.addSubItem(m_buy_subItem);

	}

	public void init() {
		m_bm_close = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_sp_beijing01 = UIWindows.createImage("/img/newui/beibaobj_2.gnp");
//		m_sp_beijing02 = UIWindows.createImage("/img/newui/yaoqianshuxbjk_1.gnp");
		m_bitmap_title = UIWindows.createImage("/img/newui/shangcheng.gnp");
		m_bm_anniu01 = UIWindows.createImage("/img/newui/anniu_6.gnp");
		m_bm_anniu02 = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		m_bm_nochoose = UIWindows.createImage("/img/newui/biaoqianye_2.gnp");
		m_bm_choose = UIWindows.createImage("/img/newui/biaoqianye_1.gnp");
		m_bm_mm = UIWindows.createImage("/img/newui/shangchengmn_1.gnp");//商城美女
		m_bm_shuangchong = UIWindows.createImage("/img/newui/shangchengyuanbao3.gnp");//
		m_bm_chunjie = UIWindows.createImage("/img/newui/shangchengyuanbao1.gnp");//
		m_picture_back = UIWindows.createImage("/img/newui/xiaobeijing_1.gnp");
		m_button_back = UIWindows.createImage("/img/newui/anniu_2.gnp");
		m_bm_left = UIWindows.createImage("/img/newui/haoyoufyan_2.gnp");
		m_bm_right = UIWindows.createImage("/img/newui/haoyoufyan_1.gnp");
		//图标
		m_shangpin = UIWindows.createImage("/img/newui/wupinlan.gnp");
		//热卖。打折。新品
		m_bm_remai = UIWindows.createImage("/img/newui/shangchengrm_1.gnp");
		m_bm_xinpin = UIWindows.createImage("/img/newui/shangchengxp_1.gnp");
		m_bm_dazhe = UIWindows.createImage("/img/newui/shangchengdz_1.gnp");

		m_bitmap_beijing = UIWindows.createImage("/img/icon/64X64kuangzi.gnp");
	}

	public void open(byte index) {
		if(index == 0){
			if(flag == false){
				shopLook();
				flag = true;
			}else{
				if(m_sp_frame != null){
					DWControlsManager.getInstance().addControl(m_sp_frame);
				}else{
					return;
				}
			}
		}
//		else if(index == 1){
//			buyItem();
//		}

	}

	public void close(byte index) {
		if(index == 0){
			flag=false;
			num = 0;
			DWControlsManager.getInstance().removeControl(m_sp_frame);
		}else if(index == 1){
			DWControlsManager.getInstance().removeControl(m_buy_frame);
		}

	}

	public void dispose() {


	}

	public void logic()
	{
		// TODO Auto-generated method stub

	}

	public int m_tab_size = 0;
	public int m_item_size  =0;
	public Item[] m_shop_item;
	public List<Item> m_shop_getItem = new ArrayList<Item>();
	public ArrayList<String> strs = new ArrayList<String>();
	public Map<String,List<Item>> map = new TreeMap<String, List<Item>>();
	public List<Item> m_VipShop_item = new ArrayList<Item>();//加入到map中
	public int m_type = 0;
	public static VipShop[] m_vipShop;
	public VipShop m_buy_vipShop;
	public int m_shop_status =0;
	/**
	 * 打开道具商城界面
	 * @param dis
	 * @throws IOException
	 */
	public void recvOpenShop(DataInputStream dis) throws IOException{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_道具商城);
		try {
			byte type = dis.readByte();
			m_type = type;
			byte size = dis.readByte();
			Item[] m_item = new Item[size];
			m_vipShop = new VipShop[size];
			for(int i =0;i<size;i++){
				VipShop vipShop = new VipShop();
				m_item[i] = new Item();
				vipShop.m_vipLevel = dis.readByte();//
				vipShop.m_canBuy = dis.readByte();//
				vipShop.m_surplus = dis.readByte();//
			//	m_item[i] = Item.recvItemFormServer(dis);
				m_item[i].m_guid = dis.readLong();
				m_item[i].m_key = dis.readUTF();
				m_item[i].m_name = dis.readUTF();
				m_item[i].m_iconId = (int)dis.readShort();
				m_item[i].m_border = (int)dis.readShort();
				m_item[i].m_yuanbaoPrice = dis.readInt();
				m_item[i].m_label_left = dis.readByte();
				m_item[i].m_label_right = dis.readByte();
				m_item[i].m_dpinzhi = true;
				m_item[i].m_dbangding = true;
				m_vipShop[i] = vipShop;
			}
			m_shop_status = dis.readByte();
//			m_shop_status = 2;
			m_shop_item = m_item;
			m_item_size = size;
			m_item =null;

			if(num == 0){
				UIWindows.getInstance().m_shop.open((byte)0);
			}else{
				if(DWControlsManager.getInstance().contains(m_sp_frame) == false && m_sp_frame != null){
					DWControlsManager.getInstance().addControl(m_sp_frame);
				}
				refreshShop();
			}
			num=1;
		} catch (Exception e) {
			Tools.debug(e);
		}
	}
	/**
	 * 查看是否成功
	 */
	public void recvLookBuyItemSucceed(DataInputStream dis) throws IOException{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_道具商城);
		try {
			Item m_look_item = new Item();
			m_look_item = Item.recvItemFormServer(dis);
			if(DWControlsManager.getInstance().contains(m_sp_frame)){
				buyItem(m_look_item);
			}else if(DWControlsManager.getInstance().contains(UIWindows.getInstance().m_vip.m_vip_frame)){
				UIWindows.getInstance().m_vip.lookLibao(m_look_item);
				//UIVip.lookLibao(m_look_item);
			}
		} catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 购买是否成功
	 * @param dis
	 * @throws IOException
	 */
	public void recvBuyItemSucceed(DataInputStream dis) throws IOException{
		try {
			byte state = dis.readByte();
			switch(state){
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"未知错误");
				break;
			case 1:
				byte yuabaonum = dis.readByte();
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"元宝不够买的数量");
//				if(DWGameManager.getInstance().m_role.m_rmb == 0){
					final DWMessageBox mb = new DWMessageBox("提示窗口", "是否现在进行充值，取得vip资格？");
					m_sp_frame.addControl(mb);
					mb.addListener(new DWListener() {

						public void OnDoubleClick() {
						}

						public void OnClick() {
							if(mb.getResult() == DWMessageBox.SOFTKEY_OK){
								//注释掉。。
//								if (ChannelOperation.isChanneSdkChongZhi) {
//									ChannelOperation.sdkPay();
//								}
//								else {
//									UIWindows.getInstance().m_shop.close((byte)0);
//									ChannelOperation.openChongZhiWindow();
//								}
								m_sp_frame.removeControl(mb);
							}else if(mb.getResult() == DWMessageBox.SOFTKEY_BACK){
								m_sp_frame.removeControl(mb);
							}

						}
					});
//				}
				break;
			case 2:
				byte levle = dis.readByte();
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"vip级别不够");
				break;
			case 3:
				byte keyibuy = dis.readByte();
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"当前vip等级不够买这么多道具");
				break;
			case 4:
				byte shengyushuliang  = dis.readByte();
//				m_buy_vipShop.m_surplus =shengyushuliang;
				m_vipShop[m_index].m_surplus = shengyushuliang;
				m_listBox_tb_shiyong[m_index].setText("今天还可以购买"+(m_vipShop[m_index].m_canBuy-shengyushuliang)+"个");
				m_sp_yuanbao.setText("当前元宝："+DWGameManager.getInstance().m_role.m_rmb);
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"成功");
				break;
			case 5:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"购买次数用尽，明天继续购买");
				break;
			case 6:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"背包已满！");
				break;
			}
		} catch (Exception e) {
			Tools.debug(e);
		}
	}

//	public static int SHOP_QUANBU = 0;//全部
//	public static int SHOP_ZHANDOU = 1;//战斗
//	public static int SHOP_SHENGHUO = 2;//生活
//	public static int SHOP_QIZHEN = 3;//奇珍
}
